#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>

#define MAXBUFSIZE 128

int main () {
  // Check opening file with completely bogus filename.
  int tmp = open("badfilename", O_RDWR);
  if (tmp < 0) {
    perror("Error opening mailbox");
  }

  // Write to NULL.
  tmp = open("/dev/mailbox0", O_RDWR);
  if (write(tmp, NULL, 5) < 0) { // Write.
    perror("Avoided writing to NULL");
  }
  if (write(tmp, (void*)0xfffffffffff, 5) < 0) { // Write.
    perror("Avoided writing to huge address");
  }
  close(tmp);

  // Read into NULL.
  tmp = open("/dev/mailbox1", O_RDWR);
  if (read(tmp, NULL, 5) < 0) { // Read.
    perror("Avoided reading into NULL");
  }
  if (read(tmp, (void*)0xffffffffff, 5) < 0) { // Read.
    perror("Avoided reading into huge address");
  }
  close(tmp);
}
